﻿using OMG.Fill.Mulberry.Model;
using OMG.Fill.Mulberry.Model.Ent;
using OMG.Fill.Mulberry.Service;
using OMG.Fill.Mulberry.UI.ActionSafety;
using ProjectShare;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Security;

namespace OMG.Fill.Mulberry.UI.Controllers
{
    public class AccountController : ApiController
    {
        public string Get(int id)
        {
            return CustomFun.GetGuid();
        }
        /// <summary>
         /// 登录
         /// </summary>
         /// <param name="model"></param>
         /// <returns></returns>
        public ResResult<UserModel> Post(LoginModel model)
        {
            ResResult<UserModel> userinfo = new ResResult<UserModel>();
            UserServices user = new UserServices();
            userinfo = user.LoginUser(model.Account, model.Passwords);
            if (userinfo.model != null)
            {
                FormsAuthentication.SetAuthCookie(userinfo.model.Id.ToString(), model.IsRember);
            }
            return userinfo;
        }

        /// <summary>
        /// 退出登录
        /// </summary>
        /// <returns></returns>
        [ApiActionAuthorize("退出登录")]
        [ApiActionException]
        public ResResult<string> Get()
        {
            var s = HttpContext.Current.Request[FormsAuthentication.FormsCookieName];
            FormsAuthentication.SignOut();
            return new ResResult<string> { status = DefaultKey.SuccessResult, message = "已退出！" };
        }
    }
}
